/**
 * Created by ll on 17/11/2017.
 * type：类型：1.普通文本框 2.时间文本框 3.下拉框
 */
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Radio, Select, Checkbox, TimePicker } from 'antd'
import moment from 'moment'
import style from '../../containers/Detail/style.less'
import store from 'store'
import { createForm } from 'rc-form'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')
const CheckboxGroup = Checkbox.Group
const RadioGroup = Radio.Group
const FormItem = Form.Item
const Option = Select.Option
const format = 'HH:mm'

class AutoForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    autoRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    selectChange: PropTypes.func,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
    isDisabled: false,
  }
  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   openSelect = (value) => {
     console.log(`selected ${value}`)
     this.props.selectChange(value)
   }

   onChange = (e) => {
    console.log('radio checked', e.target.value);
    this.setState({
      value: e.target.value,
    });
  }
  relaxChange = (value) => {
    if (value === "0") {
      this.setState({
        isDisabled: true,
      })
    }
    if (value === "2") {
      this.setState({
        isDisabled: false,
      })
    }
  }
  render() {
  //  console.log(this.props)
    const { autoRuleDetail={}, maction } = this.props
    // typeof autoRuleDetail.customerType
    console.log(typeof maction)
  //  console.log(typeof maction)
    let [customerTypeSelct,ruleRelationshipSelect,relationNumberSelect,isEnableRadio] = [ , , ,"0"]
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      customerTypeSelct = String(autoRuleDetail.customerType)
      ruleRelationshipSelect = String(autoRuleDetail.ruleRelationship)
      relationNumberSelect = String(autoRuleDetail.relationNumber)
      isEnableRadio = String(autoRuleDetail.isEnable)
    }
    // const { action } = this.props.parsed
    const { getFieldDecorator } = this.props.form
    // const { autoCompleteResult } = this.state

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    // const formTailLayout = {
    //   labelCol: { span: 6 },
    //   wrapperCol: { span: 16, offset: 6 },
    // }
    const { businessList } = this.props
    const handNumberList = this.props.internationRule.handNumberList
    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="序号">
          {getFieldDecorator('handNumber', {
            initialValue: autoRuleDetail.handNumber || '',
            rules: [{
              required: true,
              message: '请输入序号',
            }],
          })(
            <Input placeholder="请输入序号" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelct,
          })(
            <Select onChange={this.openSelect} placeholder="请选择客户类型" {...getFieldDecorator('customerType')}>
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="业务字段">
          {getFieldDecorator('businessField', {
            initialValue: autoRuleDetail.businessField,
            rules: [{
              required: this.state.checkNick,
              message: '请选择业务字段',
            }],
          })(
            <Select
              showSearch
              placeholder="请选择业务字段"
              optionFilterProp="children"
              filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
            >
              {
                 (businessList || []).map((d, i) => {
                  return (
                    <Option key={i} value={d.name}>{d.label}</Option>
                  )
                })
              }
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="字段值">
          {getFieldDecorator('fieldValues', {
            initialValue: autoRuleDetail.fieldValues || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写字段值',
            }],
          })(
            <Input placeholder="请填写字段值" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="与其他规则关系">
          {getFieldDecorator('ruleRelationship', {
            initialValue: ruleRelationshipSelect,
          })(
            <Select placeholder="请选择与其他规则关系" onChange={this.relaxChange} {...getFieldDecorator('ruleRelationship')}>
              <Option value="0">或者</Option>
              <Option value="2">并且</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="序号选择">
          {getFieldDecorator('relationNumber', {
            initialValue: relationNumberSelect,
            rules: [{
              required: this.state.checkNick,
              message: '请选择序号',
            }],
          })(
            <Select
              showSearch
              placeholder="请选择序号"
              optionFilterProp="children"
              filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
              disabled={this.state.isDisabled}
            >
              {
                 (handNumberList || []).map((d, i) => {
                  return (
                    <Option key={i} value={String(d.id)}>{d.handNumber}</Option>
                  )
                })
              }
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange} {...getFieldDecorator('isEnable')}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

class NoneForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    otherRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
  }
  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   onChange = (date, dateString) => {
     console.log(date, dateString)
   }
  render() {
    const { otherRuleDetail={}, maction } = this.props
    // typeof otherRuleDetail.customerType
    let [customerTypeSelect,isEnableRadio,recoveryTime,remindTime] = [ ,"0",null,null]
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      [recoveryTime, remindTime] = [moment(otherRuleDetail.recoveryTime, 'HH:mm'), moment(otherRuleDetail.remindTime, 'HH:mm')]
      customerTypeSelect = String(otherRuleDetail.customerType)
      isEnableRadio = String(otherRuleDetail.isEnable)
      console.log(customerTypeSelect);
    }
    const { action } = this.props.parsed
    const { getFieldDecorator } = this.props.form

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    const formTailLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16, offset: 6 },
    }
    const { businessList } = this.props
    const handNumberList = this.props.internationRule.handNumberList

    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelect,
          })(
            <Select placeholder="请选择客户类型" {...getFieldDecorator('customerType')}>
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="跟进时间未跟进天数">
          {getFieldDecorator('followDay', {
            initialValue: otherRuleDetail.followDay || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写跟进时间未跟进天数',
            }],
          })(
            <Input placeholder="请填写跟进时间未跟进天数" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="揽入后未跟进天数">
          {getFieldDecorator('getDay', {
            initialValue: otherRuleDetail.getDay || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写揽入后未跟进天数',
            }],
          })(
            <Input placeholder="请填写揽入后未跟进天数" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="回收公海时间">
          {getFieldDecorator('recoveryTime', {
            initialValue: recoveryTime,
            rules: [{
              required: false,
              message: '请选择回收公海时间!',
            }],
          })(
            <TimePicker format={format} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="提醒时间">
          {getFieldDecorator('remindTime', {
            initialValue: remindTime,
            rules: [{
              required: false,
              message: '请选择提醒时间!',
            }],
          })(
            <TimePicker format={format} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange} {...getFieldDecorator('isEnable')}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

class QuitForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    otherRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
  }
  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   onChange = (date, dateString) => {
     console.log(date, dateString)
   }
  render() {
    const { otherRuleDetail={}, maction } = this.props
    // typeof otherRuleDetail.customerType
    let [customerTypeSelect,customerStatusSelect,isEnableRadio,recoveryTime,remindTime] = [ , ,"0",null,null]
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      [recoveryTime, remindTime] = [moment(otherRuleDetail.recoveryTime, 'HH:mm'), moment(otherRuleDetail.remindTime, 'HH:mm')]
      customerTypeSelect = String(otherRuleDetail.customerType)
      customerStatusSelect = String(otherRuleDetail.customerStatus)
      isEnableRadio = String(otherRuleDetail.isEnable)
    }
    const { action } = this.props.parsed
    const { getFieldDecorator } = this.props.form

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    const formTailLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16, offset: 6 },
    }
    const { businessList } = this.props
    const handNumberList = this.props.internationRule.handNumberList

    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelect,
          })(
            <Select placeholder="请选择客户类型" {...getFieldDecorator('customerType')}>
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="客户状态">
          {getFieldDecorator('customerStatus', {
            initialValue: customerStatusSelect,
          })(
            <Select placeholder="请选择客户状态" {...getFieldDecorator('customerStatus')}>
              <Option value="0">全部</Option>
              <Option value="1">部分</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="回收公海时间">
          {getFieldDecorator('recoveryTime', {
            initialValue: recoveryTime,
            rules: [{
              required: false,
              message: '请选择回收公海时间!',
            }],
          })(
            <TimePicker format={format} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="提醒时间">
          {getFieldDecorator('remindTime', {
            initialValue: remindTime,
            rules: [{
              required: false,
              message: '请选择提醒时间!',
            }],
          })(
            <TimePicker format={format} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange} {...getFieldDecorator('isEnable')}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

class GetForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    otherRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
  }
  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   onChange = (date, dateString) => {
     console.log(date, dateString)
   }
  render() {
    const { otherRuleDetail={}, maction } = this.props
    // typeof otherRuleDetail.customerType
    let [customerTypeSelect,customerStatusSelect,isEnableRadio,recoveryTime,remindTime] = [ , ,"0",null,null]
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      [recoveryTime, remindTime] = [moment(otherRuleDetail.recoveryTime, 'HH:mm'), moment(otherRuleDetail.remindTime, 'HH:mm')]
      customerTypeSelect = String(otherRuleDetail.customerType)
      customerStatusSelect = String(otherRuleDetail.customerStatus)
      isEnableRadio = String(otherRuleDetail.isEnable)
    }
    const { action } = this.props.parsed
    const { getFieldDecorator } = this.props.form

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    const formTailLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16, offset: 6 },
    }
    const { businessList } = this.props
    const handNumberList = this.props.internationRule.handNumberList

    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelect,
          })(
            <Select placeholder="请选择客户类型" {...getFieldDecorator('customerType')}>
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="揽同天数">
          {getFieldDecorator('getDay', {
            initialValue: otherRuleDetail.getDay || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写不能连续“揽”同一个客户的天数',
            }],
          })(
            <Input placeholder="请填写不能连续“揽”同一个客户的天数" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="踢再揽天数">
          {getFieldDecorator('followDay', {
            initialValue: otherRuleDetail.followDay || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写被踢出的客户再次被其他人揽入的天数设置',
            }],
          })(
            <Input placeholder="请填写被踢出的客户再次被其他人揽入的天数设置" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange} {...getFieldDecorator('isEnable')}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

class TimeForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    otherRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
  }

  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   onChange = (date, dateString) => {
     console.log(date, dateString)
   }
  render() {
    const { otherRuleDetail={}, maction } = this.props
    let optionsList=[]
    if(otherRuleDetail.openCycle){
        const openCycleCheck = otherRuleDetail.openCycle
        optionsList = [...openCycleCheck]
    }

    let [customerTypeSelect,customerStatusSelect,isEnableRadio,recoveryTime,remindTime] = [ , ,"0",null,null]
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      [recoveryTime,remindTime] = [moment(otherRuleDetail.recoveryTime, 'HH:mm'), moment(otherRuleDetail.remindTime, 'HH:mm')]
      customerTypeSelect = String(otherRuleDetail.customerType)
      customerStatusSelect = String(otherRuleDetail.customerStatus)
      isEnableRadio = String(otherRuleDetail.isEnable)
    }

    const plainOptions = [
      { label: '周一', value: '1' },
      { label: '周二', value: '2' },
      { label: '周三', value: '3' },
      { label: '周四', value: '4' },
      { label: '周五', value: '5' },
      { label: '周六', value: '6' },
      { label: '周日', value: '7' },
    ]
    const { action } = this.props.parsed
    const { getFieldDecorator } = this.props.form

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    const formTailLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16, offset: 6 },
    }
    const { businessList } = this.props
    const handNumberList = this.props.internationRule.handNumberList
    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelect,
          })(
            <Select placeholder="请选择客户类型" {...getFieldDecorator('customerType')}>
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="开始时间设置">
          {getFieldDecorator('recoveryTime', {
            initialValue: recoveryTime,
            rules: [{
              required: false,
              message: '请选择揽入客户开始时间设置!',
            }],
          })(
            <TimePicker format={format} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="结束时间设置">
          {getFieldDecorator('remindTime', {
            initialValue: remindTime,
            rules: [{
              required: false,
              message: '请选择揽入客户结束时间设置!',
            }],
          })(
            <TimePicker format={format} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="开放周期">
          {getFieldDecorator('openCycle', {
            initialValue: optionsList,
          })(
            <CheckboxGroup options={plainOptions} onChange={this.onChange} />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange} {...getFieldDecorator('isEnable')}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

class HoldForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    otherRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
  }
  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   onChange = (date, dateString) => {
     console.log(date, dateString)
   }
  render() {
    const { otherRuleDetail={}, maction } = this.props
    // typeof otherRuleDetail.customerType
    let [customerTypeSelect,customerStatusSelect,isEnableRadio,recoveryTime,remindTime] = [ , ,"0",null,null]
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      [recoveryTime, remindTime] = [moment(otherRuleDetail.recoveryTime, 'HH:mm'), moment(otherRuleDetail.remindTime, 'HH:mm')]
      customerTypeSelect = String(otherRuleDetail.customerType)
      customerStatusSelect = String(otherRuleDetail.customerStatus)
      isEnableRadio = String(otherRuleDetail.isEnable)
    }
    const { action } = this.props.parsed
    const { form } = this.props
    const { getFieldDecorator } = form

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    const formTailLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16, offset: 6 },
    }
    const { businessList } = this.props
    const handNumberList = this.props.internationRule.handNumberList

    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelect,
          })(
            <Select placeholder="请选择客户类型">
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="拥有最大客户数量">
          {getFieldDecorator('getDay', {
            initialValue: otherRuleDetail.getDay || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写拥有最大客户数量',
            }],
          })(
            <Input placeholder="请填写拥有最大客户数量" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

class InForm extends Component { // 企业表单提交
  static propTypes = {
    form: PropTypes.any,
    otherRuleDetail: PropTypes.object,
    parsed: PropTypes.object,
    location: PropTypes.object,
  }

  state = {
    confirmDirty: false,
    autoCompleteResult: [],
  }
  handleSubmit = (e) => {
    e.preventDefault()
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values)
      }
    })
  }
  handleConfirmBlur = (e) => {
    const value = e.target.value
    this.setState({ confirmDirty: this.state.confirmDirty || !!value })
  }
  checkConfirm = (rule, value, callback) => {
    const form = this.props.form
    if (value && this.state.confirmDirty) {
      form.validateFields(['confirm'], { force: true })
    }
    callback()
  }

  handleWebsiteChange = (value) => {
    let autoCompleteResult
    if (!value) {
      autoCompleteResult = []
    } else {
      autoCompleteResult = ['.com', '.org', '.net'].map(domain => `${value}${domain}`)
    }
    this.setState({ autoCompleteResult })
  }

  handleChange = (value) => {
    console.log(`selected ${value}`)
  }

  radioOnChange = (e) => {
    console.log('radio checked', e.target.value)
    this.setState({
      value: e.target.value,
    })
  }

   onChange = (date, dateString) => {
     console.log(date, dateString)
   }
  render() {
    const { otherRuleDetail={}, maction } = this.props
    // typeof otherRuleDetail.customerType
    let customerTypeSelect,customerStatusSelect,isEnableRadio=0,recoveryTime=null,remindTime=null
    if (maction === '1') {
      // this.props.form.resetFields()
    }
    if (maction === '2') {
      [recoveryTime, remindTime] = [moment(otherRuleDetail.recoveryTime, 'HH:mm'), moment(otherRuleDetail.remindTime, 'HH:mm')]
      customerTypeSelect = String(otherRuleDetail.customerType)
      customerStatusSelect = String(otherRuleDetail.customerStatus)
      isEnableRadio = String(otherRuleDetail.isEnable)
    }
    // const { action } = this.props.parsed
    const { getFieldDecorator } = this.props.form
    const { action } = this.props.parsed
    const { form } = this.props

    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    }
    // const formTailLayout = {
    //   labelCol: { span: 6 },
    //   wrapperCol: { span: 16, offset: 6 },
    // }
    //const { businessList } = this.props
    // const handNumberList = this.props.internationRule.handNumberList

    return (
      <Form onSubmit={this.handleSubmit}>
        <FormItem {...formItemLayout} label="客户类型">
          {getFieldDecorator('customerType', {
            initialValue: customerTypeSelect,
          })(
            <Select placeholder="请选择客户类型">
              <Option value="192">个人客户</Option>
              <Option value="185">企业客户</Option>
            </Select>
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="拥有最大天数">
          {getFieldDecorator('getDay', {
            initialValue: otherRuleDetail.getDay || '',
            rules: [{
              required: this.state.checkNick,
              message: '请填写拥有最大天数',
            }],
          })(
            <Input placeholder="请填写拥有最大天数" />
          )}
        </FormItem>
        <FormItem {...formItemLayout} label="是否启用">
          {getFieldDecorator('isEnable', {
            initialValue: isEnableRadio,
          })(
            <RadioGroup name="radiogroup" onChange={this.onChange}>
              <Radio value="1">是</Radio>
              <Radio value="0">否</Radio>
            </RadioGroup>
          )}
        </FormItem>
      </Form>
    )
  }
}

export {
  AutoForm,
  NoneForm,
  QuitForm,
  GetForm,
  TimeForm,
  HoldForm,
  InForm,
}
